{include file="public/header"}
<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header">设置我的资料</div>
        <div class="layui-card-body">
          <div class="layui-form" lay-filter="">
            <div class="layui-form-item">
              <label class="layui-form-label">昵称</label>
              <div class="layui-input-inline">
                <input name="nickname" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" value="{$item.nickname|default=''}" />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">用户名</label>
              <div class="layui-input-inline">
                <input name="username" {neq name="item.id" value="1"} disabled title="登录用户名只能超管修改，如需修改请联系超管！" {/neq} autocomplete="off" class="layui-input" type="text" value="{$item.username|default=''}" />
              </div>
            </div>
            <div class="layui-upload" id="upload-thumb">
              <label class="layui-form-label">头像</label>
              <button type="button" class="layui-btn" id="thumb">上传头像</button>
              <div class="layui-upload-list">
                <label class="layui-form-label"></label>
                <img class="layui-upload-img" id="demo1" width="100" {notempty name="$item.avatar"}src="{$item.avatar}"{/notempty} >
              </div>
              <label class="layui-form-label"></label>
              <p id="demoText"></p>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">性别</label>
              <div class="layui-input-block">
                <input type="radio" name="gender" value="1" title="男" {eq name="item.gender" value="1"}checked {/eq} />
                <input type="radio" name="gender" value="2" title="女" {eq name="item.gender" value="2"}checked {/eq} />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">手机号</label>
              <div class="layui-input-inline">
                <input name="phone" lay-verify="phone" placeholder="请输入" autocomplete="off" class="layui-input" type="text" value="{$item.phone|default=''}" />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">密码</label>
              <div class="layui-input-inline">
                <input name="password" placeholder="请输入密码" autocomplete="off" class="layui-input" type="password">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">重复密码</label>
              <div class="layui-input-inline">
                <input name="repassword"  placeholder="请再次输入密码" autocomplete="off" class="layui-input" type="password">
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-input-block">
                <input type="hidden" name="id" id="id" value="{$item.id}">
                <input type="hidden" name="avatar" id="avatar" value="{$item.avatar|default=''}" />
                <button class="layui-btn" lay-submit lay-filter="Lay-app-form-submit" id="Lay-app-form-submit">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  layui.use(['layer', 'form', 'upload'], function() {
    var $ = layui.$
            ,form = layui.form
            ,upload = layui.upload
            ,layer = layui.layer;
    // 监听提交
    form.on('submit(Lay-app-form-submit)', function(data){
      var field = data.field;
      $.ajax({
        url:"{:url('admin/profile')}",
        type:'post',
        data:{'field':field},
        success:function(res){
          if(res.code == 0){
            layer.msg(res.msg,{icon:1});
          } else {
            return layer.msg(res.msg,{icon:5});
          }
        }
      });
    });
    var id = $("#id").val();
    var uploadInst = upload.render({
      elem: '#thumb'
      ,url: "{:url('uploadFile/UploadAvatar')}"
      ,data: {id:id, avatar:$("#avatar").val()}
      ,done: function(res){
        if(res.code == 0) {
          layer.msg(res.msg);
          $('#demo1').attr('src',res.data.thumb_path);
          $('#avatar').val(res.data.thumb_path);
        }else{
          layer.msg(res.msg);
        }
      }
      ,error: function(){
        var demoText = $('#demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function(){
          uploadInst.upload();
        });
      }
    });
  });
</script>
{include file="public/footer" /}